<?php

/* 分销管理 */
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\facade\Db;

class AgentController extends AdminBaseController
{

        
    public function index()
    {
        
        $data = $this->request->param();
        $map=[];


        $uid=isset($data['uid']) ? $data['uid']: '';
        if($uid!=''){
            $map[]=['uid','=',$uid];
        }
		
		
		$one=isset($data['one']) ? $data['one']: '';
        if($one!=''){
            $map[]=['one','=',$one];
        }
        
        $list = Db::name('agent')
            ->where($map)
            ->order("addtime desc")
            ->paginate(20);
        $list->each(function($v,$k){
           $v['userinfo']= getUserInfo($v['uid']);
           
           if($v['one']){
               $oneinfo=getUserInfo($v['one']);
               $v['oneinfo']=$oneinfo;
           }

           return $v; 
        });
        $list->appends($data);
        
        $page = $list->render();
        $this->assign("page", $page);
            
        $this->assign('list', $list);

        return $this->fetch();
    }

    public function profit()
    {
        
        $data = $this->request->param();
        $map=[];

        $map[]=['one_p','<>',0];
        
        $uid=isset($data['uid']) ? $data['uid']: '';
        if($uid!=''){
            $map[]=['uid','=',$uid];
        }
        
        
        $list = Db::name('agent_profit')
            ->where($map)
            ->order("uid desc")
            ->paginate(20);
        $list->each(function($v,$k){
           $v['userinfo']= getUserInfo($v['uid']);
           return $v; 
        });
        $list->appends($data);
        
        $page = $list->render();
        $this->assign("page", $page);
            
        $this->assign('list', $list);


        return $this->fetch();
    }
    
    public function rules()
    {
        
        $data = $this->request->param();
        $map=[];

        $map[]=['one_p','<>',0];
        
        $uid=isset($data['uid']) ? $data['uid']: '';
        if($uid!=''){
            $map[]=['uid','=',$uid];
        }
        
        
        $list = Db::name('agent_profit')
            ->where($map)
            ->order("uid desc")
            ->paginate(20);
        $list->each(function($v,$k){
           $v['userinfo']= getUserInfo($v['uid']);
           return $v; 
        });
        $list->appends($data);
        
        $page = $list->render();
        $this->assign("page", $page);
            
        $this->assign('list', $list);


        return $this->fetch();
    }


}